home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
UTIL
/
PROGRAMMING
/
GAMESUITE
/
GameSuite
/
Utilities
/
Hammer
/
FDecSource
< prev
next >
Wrap
Text File
|
1995-01-20
|
5KB
|
346 lines
#name fdecomp
#type &ffc
#base 0
; This file should be compiled with ExtAsm
struct v {
.sizeof
}
macro getbyte
{
STMFD R13!,{R1}
MOV R1,R6
SWI XOS_BGet
LDMFD R13!,{R1}
BCS overrunerr
}
macro getword
{
STMFD R13!,{R1-R2}
MOV R2,#0
MOV R1,R6
SWI XOS_BGet
ORRCC R2,R2,R0
SWICC XOS_BGet
ORRCC R2,R2,R0,LSL #8
SWICC XOS_BGet
ORRCC R2,R2,R0,LSL #16
SWICC XOS_BGet
ORRCC R0,R2,R0,LSL #24
LDMFD R13!,{R1-R2}
}
macro putbyte
{
STMFD R13!,{R0}
ADD R10,R10,#1
MOV R0,R10
translate
MOV R1,R0
LDMFD R13!,{R0}
STRB R0,[R1]
}
macro translate
{
CMP R7,#0
BEQ _transend
SUB R0,R0,R7
MOV R1,R0,LSL #2
SUBS R0,R0,R8,LSR #2
ADDPL R1,R1,#1
SUBPL R1,R1,R8
SUBS R0,R0,R8,LSR #2
ADDPL R1,R1,#1
SUBPL R1,R1,R8
SUBS R0,R0,R8,LSR #2
ADDPL R1,R1,#1
SUBPL R1,R1,R8
MOV R0,R1
ADD R0,R0,R7
._transend
}
;init conditions
;R0 points to the filename
;R1 points to a path variable, or =0
;exits with R2 = size of decompressed file
; R3 = address to return to after allocation
.init
STMFD R13!,{R1,R4-R7,R14}
MOV R7,R0
BL openfile
ADRVS R3,traperr
LDMVSFD R13!,{R1,R4-R7,PC}
getword
LDMCSFD R13!,{R1,R4-R7,R14}
BCS fileerr
MOV R1,R0
getword
LDMCSFD R13!,{R1,R4-R7,R14}
BCS fileerr
BL closefile
BIC R1,R1,#&FFFF<<16
LDR R2,idcode
CMP R1,R2
LDMNEFD R13!,{R1,R4-R7,R14}
BNE nothmr
MOV R2,R0
MOV R0,R7
MOV R3,PC
LDMFD R13!,{R1,R4-R7,PC} ;drops through via R3
;entry conditions
;R0 = filename
;R1 = path variable or 0
.entry
STMFD R13!,{R3-R11,R14}
MOV R10,R2
BL openfile
LDMVSFD R13!,{R3-R11,PC}
getword
MOV R7,R0
BIC R0,R0,#&FFFF<<16
LDR R1,idcode
CMP R1,R0
BNE nothmr2
getword
ADD R0,R0,#3
BIC R0,R0,#3
MOV R9,R0
MOV R8,R9 ;used as a constant
ADD R9,R10,R9; R9 is the end limit marker
MOV R0,R7
TST R0,#1<<24
MOV R7,R10
MOVEQ R7,#0
SUB R10,R10,#1; align for putbyte
SUB R9,R9,#1 ; likewise
.loop1
getbyte
CMP R0,#&10
BLT type1
CMP R0,#&20
BLT type2
CMP R0,#&40
BLT type3
CMP R0,#&80
BLT type4
;drops through
.type5
CMP R0,#&FF
BEQ overrunerr
MOV R1,R0
getbyte
AND R2,R1,#&78
MOV R2,R2,LSR #3
ADD R2,R2,#2
AND R3,R1,#&7
ADD R3,R0,R3,LSL #8
SUB R3,R10,R3
.loop7
MOV R0,R3
translate
LDRB R0,[R0]
putbyte
ADD R3,R3,#1
SUBS R2,R2,#1
BGT loop7
.typeins
CMP R10,R9
BLT loop1
BLNE inconserr
getbyte
CMP R0,#&FF
BNE underrunerr
.decompend
BL closefile
MOV R2,#&FFF
LDMFD R13!,{R3-R11,PC}
.type1 ;&00-&0F
MOV R2,R0
CMP R2,#15
ADDNE R2,R2,#2
MOVEQ R2,#256
getbyte
.loop2
putbyte
SUBS R2,R2,#1
BGT loop2
B typeins
.type2 ;&10-&1F
MOV R2,R0
AND R2,R2,#&F
ADD R2,R2,#1
.loop3
getbyte
putbyte
SUBS R2,R2,#1
BGT loop3
B typeins
.type3 ;&20-&3F
MOV R1,R0
getbyte
AND R2,R1,#&1C
MOV R2,R2,LSR #2
ADD R2,R2,#2
AND R3,R1,#&3
ADD R3,R0,R3,LSL #8
SUB R3,R10,R3
.loop5
MOV R0,R3
translate
LDRB R0,[R0]
putbyte
SUB R3,R3,#1
SUBS R2,R2,#1
BGT loop5
B typeins
.type4 ;&40-&7F
MOV R1,R0
getbyte
AND R2,R1,#&38
MOV R2,R2,LSR #3
ADD R2,R2,#2
AND R4,R1,#&06
MOV R4,R4,LSR #1
CMP R4,#2
ADDGE R4,R4,#1
AND R3,R1,#&1
ADD R3,R0,R3,LSL #8
SUB R5,R10,R3
MOV R1,#1
MOV R4,R1,LSL R4
MOV R3,#0
.loop6
ADD R0,R5,R3,ASR #2
translate
LDRB R0,[R0]
putbyte
ADD R3,R3,R4
SUBS R2,R2,#1
BGT loop6
B typeins
.openfile
STMFD R13!,{R0-R2,R14}
MOV R2,R1
MOV R1,R0
MOV R0,#&4C
CMP R2,#0
ORRNE R0,R0,#2
SWI XOS_Find
MOVVS R6,#0
LDMVSFD R13!,{R1-R3,PC}
MOV R6,R0
LDMFD R13!,{R0-R2,PC}
.closefile
STMFD R13!,{R0-R1,R14}
MOV R0,#0
MOV R1,R6
CMP R6,#0
SWINE XOS_Find
MOV R6,#0
LDMFD R13!,{R0-R1,PC}^
.nothmr
ADR R0,nothmrtext
MOV R1,#0
.err
ADR R3,traperr
ORR R14,R14,#1<<28
MOVS PC,R14
.nothmr2
ADR R0,nothmr2text
SWI OS_GenerateError
.traperr
ADR R0,traperrtext
SWI OS_GenerateError
.overrunerr
ADR R0,overrunerrtext
ADD R0,R0,#4
SWI OS_Write0
SWI OS_NewLine
B decompend
.underrunerr
ADR R0,underrunerrtext
ADD R0,R0,#4
SWI OS_Write0
SWI OS_NewLine
B decompend
.fileerr
STMFD R13!,{R0,R14}
BL closefile
LDMFD R13!,{R0,R14}
ADR R0,fileerrtext
B err
.inconserr
STMFD R13!,{R14}
ADR R0,inconserrtext
ADD R0,R0,#4
SWI OS_Write0
SWI OS_NewLine
LDMFD R13!,{PC}
.nothmrtext
DCD &666
DCB "Decomp : Not a hammer file",0
ALIGN
.nothmr2text
DCD &666
DCB "Decomp : R0 corrupted during space allocation",0
ALIGN
.traperrtext
DCD &666
DCB "Decomp : Your error trapping is not working",0
ALIGN
.overrunerrtext
DCD &666
DCB "Decomp : Overrun - bad hammer file",0
ALIGN
.underrunerrtext
DCD &666
DCB "Decomp : Underrun - bad hammer file",0
ALIGN
.inconserrtext
DCD &666
DCB "Decomp : File length inconsistent with header",0
ALIGN
.fileerrtext
DCD &666
DCB "Decomp : File error",0
ALIGN
.idcode
DCB "Hm",0,0
.spec
DCB "Decomp 0.01",0
ALIGN
.testfile
DCB "$.testfile",0
ALIGN